﻿using Star_Helper;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class 测试_数据库测试 : System.Web.UI.Page
{
    dataFunc d = new dataFunc();
    string s = "";
    int i;
    List<object[]> list;
    protected void Page_Load(object sender, EventArgs e)
    {
        DoDB b = new DoDB();
        s = b.takeDangqianYH();
        Response.Write(s);
        //b.initSqlTable();
        //b.initTestValue();
        //b.depositShangpin("12商品dddddd", "12类别aaaa", 189, 1768,000, 109, 1766, 1000);
        //register("admin", "123456");
        //b.initSqlTable();
        //isLogin("李狗蛋","a1aa");//测试成功
        //test3();
        // Response.Write(string.Join("--", new DoDB().takeLeiBie()));
        // Response.Write(string.Join("--", new DoDB().takeShangPin("'商品07'")));
        //Response.Write("成功");
        // testyemian();
    }
    public void testyemian()
    {
        DoDom dom = new DoDom();
       // s = dom.creaJiTable(1);
        //s = dom.creadTable();
        Response.Write(s);
    }
    public void depositShangpin(string shangpin, string leibie, int danjia, int chengben, int ruku, int chuku, int yingli, int kucun)
    {
        string s = string.Format("T:{0};T:{1};N:{2};N:{3};N:{4};N:{5}", shangpin, leibie, danjia,chengben, ruku, chuku, yingli);
        d.addNewupSql(1, "TSshangpin", "shangpin,leibie,danjia,chengben,ruku,chuku,yingli", s);
        d.execSqlsTran();
    }
    public void test13()
    {
        StringBuilder sx = new StringBuilder();
        Random ran = new Random();
        for (int i = 0; i < 10; i++)
        {
            sx.Append(ran.Next(1,6) + " - ");//得到1-6之间的随机数,不包括6            
        }
        Response.Write(sx.ToString());
    }
    public void register(string sx, string sx2)
    {
        dataFunc d = new dataFunc();
        string s = string.Format("T:{0};T:{1};N:1", sx, sx2);
        d.addNewupSql(1, "TSyonghu", "yonghu,mima,quanxian", s);
        d.execSqlsTran();
        Response.Write(s);
    }

    public void isLogin(string sx, string sx2)
    {
        string s = string.Format("AND aa='{0}'", sx);

        if (new dataFunc().testColVal("Ttest", "bb", sx2, s) == 0)
        {
            Response.Write("<script> alert(\"账号密码错误\") </script>");
            Response.End();
        }
        else
        {
            Response.Write("成功");
        }

    }
    public void erlog(string s)//打印日志
    {
        string filePath = "E:\\log\\log2.txt";//这里是你的已知文件
        FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite);
        StreamWriter sw = new StreamWriter(fs);
        // fs.SetLength(0);//首先把文件清空了。
        sw.Write(s);//写你的字符串。
        sw.Close();
        fs.Close();
    }
    public void test12()
    {
        //d.testLogin("Ttest#aa,bb,cc#aa,bb",)??测试登陆信息
        dataFunc.writeDoLogs("test", "测试", "testlog", 1);
    }
    public void test11()
    {
        //  d.getNowDanhao("Ttest","aa","xsd",)???单号
        s = dataFunc.sqlServerTables();//???获取数据库表信息
        Response.Write(s);
    }
    public void test10()//???
    {
        dataFunc d = new dataFunc();
        SqlCommand conn = new SqlCommand();
        conn.CommandText = "SELECT @a1 FROM @a2 ";
        d.AddInParameter(conn, "@a1", "b");
        d.AddInParameter(conn, "@a2", "abc");
        // d.getDataTable
        string s = d.execSqlsTran("ok");
        Response.Write(s);
    }

    public void test9()//去重,会留最后一个
    {
        d.delChongfu("Ttest", "aa", "id", "and dd='3'");//条件有带主键,,要and 
        s = d.execSqlsTran("ok");
        Response.Write(s);
    }
    public void test8()//从数据库记录生成下拉框,会自动排序,并去重(下拉只有子项?)
    {
        s = d.getSelectCheckFromDb(1, "Ttest", "aa", "cc", " id < 8");
        Response.Write(new StringBuilder().AppendFormat("<select>{0}</select>", s));
    }
    public void test7()
    {
        int i2 = d.getDbMaxid("Ttest");
        // i = d.testColVal("Ttest", "aa", "sf");//测试是否包含指定值,1为存在
        i = d.testColVal("sysobjects", "name", "Ttest");//判断系统数据库是否存在某个表
        Response.Write(i + " -- ");
    }
    public void test6()//带单选的数据表的列信息
    {
        s = dataFunc.sqlServerCols("Ttest");
        Response.Write(s);
    }

    public void test5()//更新或插入值,参数3为分隔用分号
    {
        d.addNewupSql(1, "Ttest", "aa,bb", "T:7ceee;T:7c8eee", "id<5");//必须要调用执行,注释没写 (插入值时,条件不起作用,)
        s = d.execSqlsTran();
        Response.Write("9成功" + s);
    }

    public void test4()//获取单行单列,得到多个的话,默认取第一个
    {
        s = d.colVal("Ttest", "aa", "id <5");
        Response.Write(s);
    }
    public void test3()//获取单行或多行指定列list
    {
       // object[] lsi= new DoDB().takeZongE();
        list = d.colsListM("TSshangpin", "DISTINCT leibie", "id>0");
        for(int i = 0; i < list.Count; i++)
        {
            s += list[i][0]+" ";
        }
       Response.Write(s);
       // Response.Write(string.Join("--", lsi));
    }
    public void test2()//删除语句,需要execSqlsTran()执行
    {
        d.addDelSql("Ttest", "id=4");
        s = d.execSqlsTran("ok");
        Response.Write(s);
    }
    public void test1()//获取指定列集合
    {
        s = string.Join(";", d.colsList("Ttest", "aa,bb,cc", "id<6"));
        Response.Write(s);
    }

    public void test()
    {
        new DoDB().SqlEx(@"
UPDATE [dbo].[Ttest]
   SET 
       [aa] = '1111222啊啊啊'
      ,[bb] = '333地方法'
      ,[cc] = '大多fghfg'
      ,[dd] =9
 WHERE id=7");

        Response.Write("完成");
    }

    public void test11111l1()
    {
        //d.setDataTable("Ttest", "aa,bb,cc", "id<9", "DESC");
        //d.GetStoredProcCommond()
    }

}